<template>
  <div class="app-container">
    <el-form class="formList"
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      label-width="100px">
      <el-row>

        <el-form-item label="日期"
          prop="payTimeArray">
          <el-date-picker v-model="dateRange"
            type="daterange"
            align="right"
            size="small"
            style="width: 232px"
            value-format="yyyy-MM-dd"
            unlink-panels
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="门店信息"
          prop="storeId">
          <el-select v-model="queryParams.storeId"
            placeholder="请选择门店"
            clearable
            size="small"
            style="width: 232px"
            @keyup.enter.native="handleQuery">
            <el-option v-for="dict in storeInFoOptions"
              :key="dict.storeId"
              :label="dict.storeName"
              :value="dict.storeUid" />
          </el-select>
        </el-form-item>
        <!--
        <el-form-item label="结算门店"
          prop="payStoreId">
          <el-select v-model="queryParams.payStoreId"
            placeholder="请选择门店"
            clearable
            size="small"
            style="width: 232px"
            @keyup.enter.native="handleQuery">
            <el-option v-for="dict in storeInFoOptions"
              :key="dict.storeId"
              :label="dict.storeName"
              :value="dict.storeUid" />
          </el-select>
        </el-form-item>
        -->
        <el-form-item style="margin-left: 22px">
          <el-button type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh"
            size="mini"
            @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-row>

    </el-form>

    <div class="order-data-show">
      <div class="order-data-item"
        v-for="(item, index) in countInfoArr"
        :key="index"
        :class="{ 'order-data-actShow': selectIdx === index }">
        <!-- <div class="order-data-item-img"><img :src="item.img"
            alt="" /></div> -->
        <div class="order-data-item-info">
          <div class="order-data-item-label">{{ item.title }}</div>
          <div class="order-data-item-num"
            :style="{ color: item.color }">
            <span :style="{ color: item.color }"
              class="order-data-item-num">{{ item.unit }}</span>
            {{ listData[item.value] || 0 }}
          </div>
        </div>
      </div>
    </div>

    <el-row class="row-mbinfo">
      <el-col :span="1.5">
        <el-button type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport">导出</el-button>
      </el-col>

    </el-row>
    <div class="divTable">
      <el-table border
        v-loading="loading"
        :data="dataList">
        <el-table-column label="结算门店"
          align="center"
          prop="collectionName"
          min-width="160px"
          show-overflow-tooltip />
        <el-table-column label="耗卡门店"
          align="center"
          prop="cardConsumptionStoreName"
          min-width="160px"
          show-overflow-tooltip />
        <el-table-column label="耗卡时间"
          align="center"
          prop="subscribeDate"
          min-width="160" />
        <el-table-column label="耗卡项目"
          align="center"
          prop="serviceName"
          min-width="160"
          show-overflow-tooltip />
        <el-table-column label="耗卡金额(元)"
          align="center"
          prop="settlementPriceStr"
          min-width="100">
        </el-table-column>
        <el-table-column label="耗卡次数"
          align="center"
          prop="times"
          min-width="100px" />
        <el-table-column label="耗卡比列"
          align="center"
          prop="itemServicePercent"
          min-width="100px" />
        <el-table-column label="金币支付(元)"
          align="center"
          prop="payGoldCoinStr"
          min-width="100px" />
        <el-table-column label="耗卡成本(元)"
          align="center"
          prop="costPriceStr"
          min-width="100px" />
        <el-table-column label="现金支付(元)"
          align="center"
          prop="collectionPriceStr"
          min-width="100px" />
        <el-table-column label="银币支付(元)"
          align="center"
          prop="paySilverCoinStr"
          min-width="100px" />
        <el-table-column label="服务技师"
          align="center"
          prop="technicianName"
          min-width="120px"
          show-overflow-tooltip />
        <el-table-column label="客户来源"
          align="center"
          prop="sourcePlatformStr"
          min-width="160px"
          show-overflow-tooltip />
      </el-table>

      <pagination v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList" />
    </div>

  </div>
</template>

<script>
import {
  selectGroup
} from "@/api/platform/store"
import {
  financeKuaList
} from "@/api/finance/finance"

export default {
  name: "Order",
  data () {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        startTime: '',
        endTime: '',
        storeId: '',
        payStoreId: ''
      },
      dateRange: [],
      dataList: [],
      storeInFoOptions: [],

      countInfoArr: [
        {
          img: require("@/assets/images/order-icon-14.png"),
          title: "跨店收入",
          value: "kuaDianShouRu",
          color: "#E00065",
          unit: "￥",
        },
        {
          img: require("@/assets/images/order-icon-11.png"),
          title: "跨店支出",
          value: "kuaDianZhiChu",
          color: "#FFA082",
          unit: "￥",
        },
        {
          img: require("@/assets/images/order-icon-12.png"),
          title: "服务项目数",
          value: "itemCount",
          color: "#00D1B3",
          unit: "",
        },
        {
          img: require("@/assets/images/order-icon-12.png"),
          title: "人数",
          value: "manCount",
          color: "#5DA9EF",
          unit: "",
        },
      ],
      selectIdx: null,
      listData: {},
    };
  },
  watch: {
    dateRange (val) {
      if (val) {
        this.queryParams.startTime = val[0]
        this.queryParams.endTime = val[1]
      } else {
        this.queryParams.startTime = ''
        this.queryParams.endTime = ''
      }
    }
  },
  created () {
    selectGroup().then(response => {
      this.storeInFoOptions = response.data || [];
    });
    this.getList();
  },
  methods: {
    // toSearchList (idx) {
    //   this.selectIdx = idx
    //   this.queryParams.pageNum = 1;
    //   this.getList();
    // },

    getList () {
      this.loading = true;
      financeKuaList(this.queryParams).then((response) => {
        this.dataList = response.rows;
        this.total = response.total;
        this.listData.manCount = response.manCount;
        this.listData.itemCount = response.itemCount;
        this.listData.kuaDianShouRu = response.kuaDianShouRu;
        this.listData.kuaDianZhiChu = response.kuaDianZhiChu;
        this.loading = false;
      });
    },


    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.resetForm("queryForm");
      this.handleQuery();
    },

    /** 导出按钮操作 */
    handleExport () {
      let times = new Date().getTime()

      this.download(
        "prod-api/finance/kuaExport",
        {
          ...this.queryParams,
        },
        `跨店明细-${times}.xlsx`
      );
    },
  },
};
</script>
<style lang="scss" scoped>
.order-data-show {
  display: flex;
  margin: 10px 0;
  .order-data-item {
    flex: 1;
    padding: 16px 32px;
    display: flex;
    align-items: center;
    background-color: #fff;
    border-radius: 8px;
    cursor: pointer;
    &:not(:last-child) {
      margin-right: 12px;
    }
    .order-data-item-img {
      width: 68px;
      height: 68px;
      margin-right: 32px;
    }
    .order-data-item-num {
      font-size: 30px;
      color: #5da9ef;
      font-weight: 500;
      line-height: 1;
      display: flex;
      align-items: flex-end;
      .order-data-item-num-unit {
        font-size: 16px;
        margin-left: 12px;
        line-height: 1.4;
      }
    }
    .order-data-item-label {
      font-size: 16px;
      color: #999;
      line-height: 1;
      margin-bottom: 14px;
    }
  }
  .order-data-actShow {
    background-color: #f1f1f1;
    transition: all 0.3s;
  }
}
</style>
